package com.ruoyi.carShopService.controller;

import com.ruoyi.carShopService.domain.ShopOrderManage;
import com.ruoyi.carShopService.service.ShopOrderManageService;
import com.ruoyi.carShopService.util.JwtUtil;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.domain.CarMerchantPrincipal;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author：马帅帅
 * @Date ：2024/9/11 19:49
 * 订单管理
 */
@RestController
@RequestMapping("/order")
@CrossOrigin
public class ShopOrderManageController {


    @Autowired
    private ShopOrderManageService shopOrderManageService;
    @RequestMapping("/list")
    public List<ShopOrderManage> selectShopOrderManageList(@RequestHeader("token") String token) {
        System.out.println(token);

        // 解析token
        try{
            Claims claims = JwtUtil.parseJWT(token);
            String merchantIdStr = claims.getSubject();
            long merchantId = Long.parseLong(merchantIdStr);
//            System.out.println(mpId);
            //4 根据mpId查询商家信息
            return  shopOrderManageService.selectShopOrderManageList(merchantId);

//            System.out.println("merchant:" + merchant);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }


    //    搜索订单
    @RequestMapping("/query")
    public List<ShopOrderManage> selectShopOrderManageList2(@RequestBody Map<String, Object> map,@RequestHeader("token") String token) {
        // 解析token
        try{
            Claims claims = JwtUtil.parseJWT(token);
            String merchantIdStr = claims.getSubject();
            long merchantId = Long.parseLong(merchantIdStr);
            System.out.println(merchantId + "97");

            Object input = map.get("input");
            return shopOrderManageService.selectShopOrderManageList2(input,merchantId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    //通过id查询订单详情
    @RequestMapping("/selectById")
    public List<ShopOrderManage> selectById(Long ordId) {
        return shopOrderManageService.selectById(ordId);
    }


//    <!--    核销记录-->
    @RequestMapping("/list1")
    public List<ShopOrderManage> selectShopVerificationList(@RequestHeader("token") String token) {
        System.out.println(token);

        // 解析token
        try{
            Claims claims = JwtUtil.parseJWT(token);
            String merchantIdStr = claims.getSubject();
            long merchantId = Long.parseLong(merchantIdStr);

//            System.out.println(mpId);
            //4 根据mpId查询商家信息
            return shopOrderManageService.selectShopVerificationList(merchantId);

//            System.out.println("merchant:" + merchant);

        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    //搜索核销记录
    @RequestMapping("/query2")
    public List<ShopOrderManage> selectShopVerificationList2(@RequestBody Map<String, Object> map,@RequestHeader("token") String token) {

        // 解析token
        try{
            Claims claims = JwtUtil.parseJWT(token);
            String merchantIdStr = claims.getSubject();
            long merchantId = Long.parseLong(merchantIdStr);
            System.out.println(merchantId + "97");
//            System.out.println("merchant:" + merchant);
            Object input = map.get("input");
            return shopOrderManageService.selectShopVerificationList2(input,merchantId);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }


}
